﻿#pragma once
#include "GLProgram.h"
#include "VertexIndexBuffer.h"
#include "VertexData.h"
#include "MatrixBuffer.h"
#include "TextureBuffer.h"

class Primitive
{
public:
	Primitive();
	~Primitive();

	/** 刷新VAO数据 */
	void reload();

	/** 绘制数据 */
	void draw();

	/** 获取缓冲区的openGL句柄 */
	GLuint getVAO() const;

	void setProgram(std::shared_ptr<GLProgram>& program)
	{
		_program = program;
	}

	void setVertexData(std::shared_ptr<VertexData>& vertexData)
	{
		_vertexData = vertexData;
	}

	void setIndexBuffer(std::shared_ptr<IndexBuffer>& indexBuffer)
	{
		_indexBuffer = indexBuffer;
	}

	std::shared_ptr<MatrixBuffer>& matrixBuffer()
	{
		return _matrixBuffer;
	}

	void setMatrixBuffer(std::shared_ptr<MatrixBuffer>& matrixBuffer)
	{
		_matrixBuffer = matrixBuffer;
	}

	std::shared_ptr<TextureData>& textureData()
	{
		return _textureData;
	}

	void setTextureData(std::shared_ptr<TextureData>& textureData)
	{
		_textureData = textureData;
	}

private:
	/** 渲染数据缓冲区 */
	GLuint _buffersVAO;

	/** 着色器 */
	std::shared_ptr<GLProgram> _program;

	/** 主体数据(一般只放顶点数据) */
	std::shared_ptr<VertexData> _vertexData;

	/** 索引数据 */
	std::shared_ptr<IndexBuffer> _indexBuffer;

	/** 变换矩阵数据 */
	std::shared_ptr<MatrixBuffer> _matrixBuffer;

	/** 纹理数据 */
	std::shared_ptr<TextureData> _textureData;
};
